import { request } from 'umi';
import { Program } from '@/data-type'
import { BaseService } from './baseService';
class ProgramServiceImpl implements BaseService<Program> {
  async queryList(options?: { [key: string]: any; } | undefined): Promise<{ data: Program[]; }> {
    let retData = {
      data: [
        {
          id: 123456,
          programName: "集美先锋",
          firstParty: "甲方1号",
          secondParty: "乙方1号",
          programAddress: "项目地址",
          programAmount: 300000,
          programCost: 200000,
          programProfit: 100000,
          status: "ing",
          startDate: new Date('2021-10-12'),
          endDate: new Date('2022-7-1'),
        },
        {
          id: 123457,
          programName: "牡丹湖",
          firstParty: "甲方2号",
          secondParty: "乙方1号",
          programAddress: "项目地址",
          programAmount: 300000,
          programCost: 200000,
          programProfit: 100000,
          status: "ing",
          startDate: new Date('2021-10-12'),
          endDate: new Date('2022-7-1'),
        }
      ],
    }
    // console.log("访问了queryList");
    let ret: Program[] = new Array<Program>();
    await request("/program/query_list", {
      method: "POST",
      data: {
        "id": null,
      }
    }).then(response => {
      console.log("respose:", response);
      ret = response.data
    })
    return Promise.resolve({ data: ret });
    // return Promise.resolve(retData);
  }
  async deleteOne(id: number): Promise<boolean> {
    console.log("need delete id is", id);
    await request("/program/delete_one", {
      method: "DELETE",
      data: {
        id,
      }
    })
    return Promise.resolve(true);
  }
  async updateOne(entity: Program): Promise<boolean> {
    console.log("need update id is", entity);
    await request("/program/update_one", {
      method: "PUT",
      data: {
        ...entity
      }
    })
    return Promise.resolve(true);
  }
  async save(entity: Program): Promise<boolean> {
    console.log("保存成功");
    await request("/program/save_one", {
      method: "POST",
      data: {
        ...entity
      }
    })
    return Promise.resolve(true);
  }

}
export const ProgramService = new ProgramServiceImpl();